// pages/modifyPage/modifyPage.js
var $ = require('../util/commit.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ShowVerTime: true,
    VerTime: 30,
    tel: '',
    code: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  // 重制获取验证码按钮
  doVerification() {
    let that = this;
    let verTime = that.data.VerTime;
    that.interval = setInterval(function() {
      
      if (verTime > 1) {
        verTime--;
        console.log(verTime)
        that.setData({
          VerTime: verTime
        })
      } else {
        that.setData({
          VerTime: 30,
          ShowVerTime: true
        })
        clearInterval(that.interval)
      }
    }, 1000)
  },
  // 获取验证码
  GetTelVerification: function() {
    let that = this
    if (that.data.tel) {
      $.POST({
        url: 'h5SendSMS',
        data: {
          type: that.data.tarIndex,
          page: 1,
        }
      }, function(res) {
        that.setData({
          ShowVerTime: false
        })
        that.doVerification()
        if (res.code === 300) {
          wx.showToast({
            title: res.msg,
            icon: 'error'
          });
          that.setData({
            VerTime: 30,
            ShowVerTime: true
          })
        }
      }, function() {

      })
    } else {
      wx.showToast({
        title: '请填写手机号',
        icon: 'error'
      });
    }
  },
  // 手机号输入
  keyTelVal:function(e){
    let that = this;
    that.setData({
      tel:e.detail.value
    })
  }
})